//package com.fy.mq;
//
//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
//import lombok.extern.slf4j.Slf4j;
//import com.fy.pojo.entity.Coupon;
//import com.fy.pojo.entity.CouponOrder;
//import com.fy.service.CouponOrderService;
//import com.fy.service.CouponService;
//import org.springframework.amqp.rabbit.annotation.Exchange;
//import org.springframework.amqp.rabbit.annotation.Queue;
//import org.springframework.amqp.rabbit.annotation.QueueBinding;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//
//@Component
//@Slf4j
//public class customer {
//
//    @Autowired
//    private CouponService couponService;
//
//    @Autowired
//    private CouponOrderService couponOrderService;
//
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "seckill.que", durable = "true"),
//            exchange = @Exchange(name = "seckill",durable = "true"),
//            key = {"seckill"}
//    ))
//    public void listenerSuccess(CouponOrder couponOrder) {
//        log.info("监听的消息队列信息couponOrder:{}",couponOrder);
//        // 创建一个 LambdaUpdateWrapper 对象
//        boolean save = couponOrderService.save(couponOrder);
//        if(!save){
//            return;
//        }
//        LambdaUpdateWrapper<Coupon> updateWrapper = new LambdaUpdateWrapper<>();
//        updateWrapper.eq(Coupon::getId, couponOrder.getCouponId())
//                .gt(Coupon::getCouponStock, 0)  //基于乐观锁的方式判断库存防止超卖问题
//                .setSql("coupon_stock = coupon_stock - 1");
//        // 调用 update 方法进行更新
//        couponService.update(updateWrapper);
//    }
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "test.que", durable = "true"),
//            exchange = @Exchange(name = "test"),
//            key = {"test"}
//    ))
//    public void listenerTest(String msg) {
//        log.info("监听的消息队列信息test:{}",msg);
//    }
//
//}
